<?php


namespace app\diy\controller;


use app\AdminRest;
use longbingcore\permissions\AdminMenu;

class ComponentsController extends AdminRest
{
    public function List()
    {

        //By.jingshuixian
        //2019年11月23日17:43:17
        // 点击DIY底部菜单时,加载右侧的组件信息
        $returnCompoentsData = [] ;
        //载入底部菜单数据
        $DiyMenuData = longbing_init_info_data('DiyTabbar');
        //载入模块数据
        $DiyCompoentsData = longbing_init_info_data('DiyCompoents');
        //获取模块key
        $menuKey = $this->_param['key'] ?? null;

        $app_name = config('app.AdminModelList')['app_model_name'];
        //只有saas版才有这个功能
//        if(in_array($menuKey,[1,2,3,4])&&sassAuth()==0&&!in_array($app_name,['longbing_restaurant'])){
//
//            return $this->success([]) ;
//        }


        foreach ($DiyMenuData as $menuData){
            //查询底部菜单
            if($menuData['key'] == $menuKey ){
                //获取底部菜单绑定的组件
                $bind_compoents = $menuData['bind_compoents'] ;
                //加载组件信息
                foreach ($DiyCompoentsData as $compoents){

                    if (in_array($compoents['type'] , $bind_compoents)){

                        $compoents['sort'] = !empty($compoents['sort'])?$compoents['sort']:1;

                        $returnCompoentsData[] = $compoents ;
                    }
                }
            }
        }

        $returnCompoentsData = !empty($returnCompoentsData)?arraySort($returnCompoentsData,'sort','desc'):[];
        //获取有权限的
        $returnCompoentsData = getAuthCompoentsData($returnCompoentsData,$this->_uniacid);

        return $this->success($returnCompoentsData) ;
    }



}